package com.handa.documentManager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.handa.documentManager.entity.DO.OnlyofficeFileInfoDO;
import com.handa.documentManager.mapper.OnlyofficeFileInfoMapper;
import com.handa.documentManager.service.IOnlyofficeFileInfoService;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-07-22
 */
@Service
public class OnlyofficeFileInfoServiceImpl extends ServiceImpl<OnlyofficeFileInfoMapper, OnlyofficeFileInfoDO> implements IOnlyofficeFileInfoService {

    @Override
    public Integer deleteOverTimeItems() {
        // 计算 5 天前的日期
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -5);
        Date fiveDaysAgo = calendar.getTime();


        QueryWrapper<OnlyofficeFileInfoDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.lt("update_time", fiveDaysAgo); // update_time < 5天前

        int deletedCount = count(queryWrapper);

        remove(queryWrapper);

        return deletedCount;
    }

}
